package com.tanhua.dubbo.api.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.domain.db.Announcement;
import com.tanhua.domain.vo.PageResult;
import com.tanhua.dubbo.api.AnnouncementsApi;
import com.tanhua.dubbo.mapper.AnnouncementsMapper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author 大大大脸怪吖
 * @Date: Created in 10:43 2021/3/15
 */
@Service
public class AnnouncementsApiImpl implements AnnouncementsApi {

    @Autowired
    private AnnouncementsMapper announcementsMapper;
    @Override
    public PageResult queryAnnouncements(Integer page, Integer pagesize) {
        Page<Announcement> page1=new Page<>(page,pagesize);
        QueryWrapper<Announcement> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("created");
        announcementsMapper.selectPage(page1,queryWrapper);
        return new PageResult(page,pagesize, (int) page1.getTotal(),page1.getRecords());
    }

    @Override
    public Announcement findById(String id) {
        return announcementsMapper.selectById(id);
    }
}
